﻿namespace FlexField.Metadata
{
    /// <summary>
    /// The default implementation of <see cref="MetadataEntity{TKey}"/> which uses a string as a primary key.
    /// </summary>
    //public class MetadataEntity : MetadataEntity<string>
    //{
    //    /// <summary>
    //    /// Initializes a new instance of <see cref="MetadataEntity"/>.
    //    /// </summary>
    //    /// <remarks>
    //    /// The Id property is initialized to form a new GUID string value.
    //    /// </remarks>
    //    public MetadataEntity()
    //    {
    //        Id = Guid.NewGuid().ToString();
    //    }

    //    /// <summary>
    //    /// Initializes a new instance of <see cref="MetadataField"/>.
    //    /// </summary>
    //    /// <param name="entityName">The type name.</param>
    //    /// <remarks>
    //    /// The Id property is initialized to form a new GUID string value.
    //    /// </remarks>
    //    public MetadataEntity(string entityName) : this()
    //    {
    //        EntityName = entityName;
    //    }
    //}

    /// <summary>
    /// Represents the entity information in the metadata subsystem.
    /// </summary>
    /// <typeparam name="TKey">The type used for the primary key for the entity.</typeparam>
    public class MetadataEntity<TKey> where TKey : IEquatable<TKey>
    {
        /// <summary>
        /// Initializes a new instance of <see cref="MetadataEntity{TKey}"/>.
        /// </summary>
        public MetadataEntity()
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="MetadataEntity{TKey}"/>.
        /// </summary>
        /// <param name="entityName">The entity name.</param>
        public MetadataEntity(string entityName) : this()
        {
            EntityName = entityName;
        }

        /// <summary>
        /// Gets or sets the primary key for this entity.
        /// </summary>
        public virtual TKey Id { get; set; }

        /// <summary>
        /// Gets or sets the name of this entity.
        /// </summary>
        public virtual string EntityName { get; set; }

        /// <summary>
        /// Gets or sets the display name of this entity.
        /// </summary>
        public virtual string DisplayName { get; set; }

        /// <summary>
        /// A random value that must change whenever an entity is persisted to the store
        /// </summary>
        public virtual string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// Gets the <see cref="IDictionary{String, String}"/> for extended entity properties.
        /// </summary>
        public IDictionary<string, string> Properties { get; } =
            new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

        public override string ToString()
        {
            return EntityName;
        }
    }
}
